import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useMemberStore = defineStore('member', {
    // 定义初始状态
    state: () => ({
        name: '',
        email: '',
        level: 'basic',
    }),

    // 定义计算属性
    getters: {
        isPremium() {
            return this.level === 'premium';
        },
    },

    // 定义操作方法
    actions: {
        setName(name) {
            this.name = name;
        },

        setEmail(email) {
            this.email = email;
        },

        setLevel(level) {
            this.level = level;
        },
    },

    // 启用持久化
    persist: {
        key: 'member-store',
        storage: localStorage,
    },
})
